#include "stdffield.h"
#include <sstream>
#include <vector>
#include "chararray.h"
#include <string>


using namespace std;
using namespace opsrc::stdf;

template<typename T> string StdfField<T>::dString = " ";

template <typename T>
StdfField<T>::StdfField() {
    // initialize class variables to 0.
    // Any value assigned to this will indicate there is valid data!!!
    offset = 0;
    length = 0;
    totallen = 0;
}

template <typename T>
StdfField<T>::StdfField(T repData, int Offset, int len, int tlen)
:data(repData), offset(Offset), length(len), totallen(tlen) {
}

template <typename T>
StdfField<T>::StdfField(const StdfField<T> &rv ) {
   this->data = rv.data;
   this->offset = rv.offset;
   this->length = rv.length;
   this->totallen = rv.totallen;
}


template <typename T>
StdfField<T>::~StdfField() {
}



template <typename T>
void StdfField<T>::setOffset(int offset) {
	this->offset = offset;
}

template <typename T>
int StdfField<T>::getOffset() const {
	return this->offset;
}

template <typename T>
int StdfField<T>::getByteCount() const {
	return length;
}

template <typename T>
void StdfField<T>::setByteCount(int count) {
	length = count;
}

template <typename T>
T& StdfField<T>::getData()  {
    return data;	
}

template <typename T>
const T& StdfField<T>::getData() const  {
    return data;	
}

template <typename T>
void StdfField<T>::setData(T d) {
	data = d;	
}

template <typename T>
void StdfField<T>::set(T d, int offset, int len, int tlen) {
	this->setData(d);
	this->setOffset(offset);
	this->setByteCount(len);
	this->setTotalByteCount(tlen);	
}


template <typename T>
void StdfField<T>::setTotalByteCount(int l)  {
	totallen = l;
}


template <typename T>
int StdfField<T>::getTotalByteCount() const {
	return totallen;
}

template <typename T>
string StdfField<T>::getDataS() const {
    // default string data default is a blank space.
    // Specialized StdfField instance must override this function
    if (totallen > 0 ) {
        std::stringstream out;
        out << data;
        return out.str();
    }

    return dString;

}

// ---  specialization to override getDataS function

